Kate Culhane, Dept. of Ecology, Evolution, and Marine Biology, UC Santa Barbara
kathrynculhane@ucsb.edu
SUMMARY
Description and wrangling of datasets. Raw data are located in the project directory data_raw.
DATA FILE STRUCTURE
data_raw
├── field # Field/lab measurements
├── original_spreadsheets # Original data (no cleaning/proofing)
├── [...].xlxs # Original Excel files
└── data_errata.txt # Log of corrections made to .csv files
├── diet_field.csv # Stomach pump invert ID (all islands)
├── naxos_meta.csv # Site metadata (Naxos)
├── naxos_veg.csv # Vegetation quadrats (Naxos)
├── prey_meta.csv # Pitfall/sticky metadata (all islands)
├── prey_pitfall.csv # Pitfall trap invert ID (all islands)
└── prey_sticky.csv # Sticky trap invert ID (all islands)
DEPENDENCIES
##### PACKAGES #####
library(tidyverse) # data manipulation & visualization
library(lubridate) # wrangling dates
library(kableExtra) # pretty tables
##### DATA #####
# Site info
meta_raw <- read_csv('data_raw/field/naxos_meta.csv')
veg_raw <- read_csv('data_raw/field/naxos_veg.csv')
# Invertebrate traps
prey_meta_raw <- read_csv('data_raw/field/prey_meta.csv',
col_types = "??cccc???????????????") %>% # dates as chr
filter(island == "Naxos")
prey_p_raw <- read_csv('data_raw/field/prey_pitfall.csv') %>%
filter(island == "Naxos")
prey_s_raw <- read_csv('data_raw/field/prey_sticky.csv') %>%
filter(island == "Naxos")
# Lizard diet
diet_raw <- read_csv('data_raw/field/diet_field.csv') %>%
filter(island == "Naxos")OUTPUT FILES
00_diet_inverts.csv - Invertebrate counts by order from lizard stomach pumping samples00_diet_matrix.csv - Site by species matrix (diet data)00_diet_veg.csv - Vegetation counts from lizard stomach pumping samples00_prey.csv - Invertebrate counts by order from sticky and pitfall trap samples00_prey_matrix.csv - Site by species matrix (invert trap data)00_prey_metadata.csv - Metadata for sticky and pitfall trap samples00_trap_veg - Vegetation cover by life form from quadrats associated with invert trapsmeta_raw %>%
arrange(use, veg)# Trap metadata
trap_veg <- prey_meta_raw %>%
select(2, 8, 11:21)
write_csv(trap_veg, "output/00_trap_veg.csv", col_names = TRUE)
trap_vegveg_raw# Trap metadata
prey_meta <- prey_meta_raw %>%
left_join(prey_p_raw[c(2,4,31)], by = c("site", "trap")) %>%
left_join(prey_s_raw[c(2,4,24)], by = c("site", "trap")) %>%
mutate(comments_p = comments.y,
comments_s = comments,
comments = comments.x,
set = dmy_hm(paste(date_set, time_set),
quiet = TRUE), # suppress warnings
collected = dmy_hm(paste(date_coll, time_coll),
quiet = TRUE), # suppress warnings
hours_open = as.numeric(collected - set)*24,
pitfall_effort = case_when(
pitfall_condition == "GOOD" ~ 1,
pitfall_condition == "FLAW" ~ 0.5,
pitfall_condition == "LOST" ~ 0),
sticky_effort = case_when(
sticky_condition == "GOOD" ~ 1,
sticky_condition == "FLAW" ~ 0.5,
sticky_condition == "LOST" ~ 0
)) %>%
select(site, set, collected, hours_open, crew, trap,
pitfall_condition, pitfall_effort, sticky_condition, sticky_effort,
comments, comments_p, comments_s)
write_csv(prey_meta, "output/00_prey_meta.csv", col_names = TRUE)
prey_meta# Pitfall trap data
prey_p <- prey_p_raw %>%
mutate(trap_type = "pitfall",
sample = paste0(site, "-P", trap)) %>%
select(-gecko, -lizard) %>% # remove columns for non-invertebrates
pivot_longer(5:28, names_to = "order", values_to = "count")
# Sticky trap data
prey_s <- prey_s_raw %>%
mutate(trap_type = "sticky",
sample = paste0(site, "-S", trap)) %>%
select(-gecko) %>% # remove columns for non-invertebrates
pivot_longer(5:22, names_to = "order", values_to = "count")
# All trap data
prey <- full_join(prey_p, prey_s) %>%
filter(count != 0) %>%
select(sample, site, trap, trap_type, order, count)
write_csv(prey, "output/00_prey.csv", col_names = TRUE)
preyprey_matrix <- prey %>%
pivot_wider(names_from = order, values_from = count) %>%
replace(., is.na(.), 0)
write_csv(prey_matrix, "output/00_prey_matrix.csv", col_names = TRUE)
prey_matrix## # A tibble: 213 x 27
## sample site trap trap_type diptera hemiptera hymenoptera coleoptera acari collembola araneae isopoda
## <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 DEMAR-P1 DEMAR 1 pitfall 1 1 8 0 0 0 0 0
## 2 DEMAR-P2 DEMAR 2 pitfall 0 1 7 1 1 0 0 0
## 3 DEMAR-P3 DEMAR 3 pitfall 1 0 1 2 0 2 1 0
## 4 DEMAR-P4 DEMAR 4 pitfall 1 0 8 1 1 0 0 1
## 5 DEMAR-P5 DEMAR 5 pitfall 0 2 7 2 2 0 0 0
## 6 DEMAR-P6 DEMAR 6 pitfall 0 1 0 3 0 0 2 0
## 7 DEMAR-P7 DEMAR 7 pitfall 2 0 9 3 2 0 0 0
## 8 DEMAR-P8 DEMAR 8 pitfall 0 2 2 0 0 0 0 0
## 9 DEMAR-P9 DEMAR 9 pitfall 0 0 1 0 1 1 0 0
## 10 DEMAR-P10 DEMAR 10 pitfall 0 1 5 2 2 0 1 0
## # ... with 203 more rows, and 15 more variables: pseudoscorpiones <dbl>, embioptera <dbl>, gastropoda <dbl>,
## # lepidoptera <dbl>, thysanura <dbl>, chilopoda <dbl>, coleoptera_larvae <dbl>, isoptera <dbl>,
## # orthoptera <dbl>, lepidoptera_larvae <dbl>, opilliones <dbl>, neuroptera <dbl>, homoptera <dbl>,
## # psocoptera <dbl>, raphidioptera <dbl>
veganNumber of samples per site:
diet <- diet_raw %>%
select(where(~ any(. != 0)), -island) # remove columns with 0 observations
diet %>%
count(site) %>%
arrange(-n) %>%
pivot_wider(names_from = site, values_from = n) %>%
kbl() %>%
kable_minimal(full_width = FALSE, position = "left")| DEMAR | WMONI | SMONI | VIGLA | EMONI | MALYKO | RACHI | SAGRI | NALYKO |
|---|---|---|---|---|---|---|---|---|
| 30 | 29 | 24 | 18 | 14 | 11 | 10 | 7 | 6 |
diet_inverts <- diet %>%
select(-c("berry":"stick","sand")) %>%
mutate(egg = insect_egg + spider_egg,
larvae = coleoptera_larvae + diptera_larvae +
lepidoptera_larvae + neuroptera_larvae) %>%
select(-c("insect_egg":"spider_egg",
"coleoptera_larvae":"neuroptera_larvae")) %>%
relocate(comments, .after = last_col()) %>%
pivot_longer("blattodea":"larvae",
names_to = "order", values_to = "count") %>%
filter(count != 0) %>%
relocate(comments, .after = last_col())
write_csv(diet_inverts, "output/00_diet_inverts.csv", col_names = TRUE)
diet_invertsNumber of samples containing each order:
count(diet_inverts, order) %>%
arrange(-n)%>%
kbl() %>%
kable_minimal(full_width = FALSE, position = "left")| order | n |
|---|---|
| coleoptera | 77 |
| hymenoptera | 67 |
| hemiptera | 66 |
| araneae | 56 |
| larvae | 41 |
| gastropoda | 33 |
| orthoptera | 27 |
| lepidoptera | 10 |
| diptera | 9 |
| isopoda | 9 |
| acari | 6 |
| blattodea | 5 |
| egg | 4 |
| thysanura | 4 |
| pseudoscorpiones | 2 |
| odonata | 1 |
| raphidioptera | 1 |
diet_matrix <- diet_inverts %>%
select(-date, -comments) %>%
mutate(order = factor(order, # order factor by n
levels = arrange(count(diet_inverts, order),-n)$order)) %>%
pivot_wider(names_from = order, values_from = count) %>%
replace(., is.na(.), 0)
write_csv(diet_matrix, "output/00_diet_matrix.csv", col_names = TRUE)
diet_matrix## # A tibble: 148 x 19
## site lizard_id coleoptera hemiptera thysanura araneae hymenoptera gastropoda lepidoptera orthoptera diptera
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 DEMAR DEMAR-518-~ 1 6 1 1 0 0 0 0 0
## 2 DEMAR DEMAR-518-~ 3 0 0 2 2 1 0 0 0
## 3 DEMAR DEMAR-518-~ 1 2 0 1 0 0 1 0 0
## 4 DEMAR DEMAR-518-~ 2 2 0 1 0 0 0 0 0
## 5 DEMAR DEMAR-518-~ 0 2 0 0 1 0 0 1 0
## 6 DEMAR DEMAR-518-~ 0 1 0 0 0 0 0 1 0
## 7 DEMAR DEMAR-518-~ 0 1 0 2 1 1 0 0 0
## 8 DEMAR DEMAR-518-~ 0 3 0 1 1 0 0 1 0
## 9 DEMAR DEMAR-518-~ 0 1 0 4 0 1 0 0 0
## 10 DEMAR DEMAR-518-~ 0 1 0 2 0 0 0 0 1
## # ... with 138 more rows, and 8 more variables: isopoda <dbl>, larvae <dbl>, egg <dbl>, acari <dbl>,
## # pseudoscorpiones <dbl>, blattodea <dbl>, odonata <dbl>, raphidioptera <dbl>
vegandiet_veg <- diet %>%
select(-c("blattodea":"gastropoda","sand")) %>%
mutate(seed = seed + seed_pod) %>%
select(-seed_pod) %>%
pivot_longer("berry":"stick",
names_to = "veg", values_to = "count") %>%
filter(count != 0) %>%
relocate(comments, .after = last_col())
write_csv(diet_veg, "output/00_diet_veg.csv", col_names = TRUE)
diet_vegNumber of samples containing each type of veg:
count(diet_veg, veg) %>%
arrange(-n)%>%
kbl() %>%
kable_minimal(full_width = FALSE, position = "left")| veg | n |
|---|---|
| flower_parts | 6 |
| stick | 6 |
| leaf | 4 |
| seed | 3 |
| berry | 2 |
devtools::session_info()## - Session info ------------------------------------------------------------------------------------------------
## setting value
## version R version 4.1.0 (2021-05-18)
## os Windows 10 x64
## system i386, mingw32
## ui RStudio
## language (EN)
## collate English_United States.1252
## ctype English_United States.1252
## tz America/Los_Angeles
## date 2021-08-02
##
## - Packages ----------------------------------------------------------------------------------------------------
## ! package * version date lib source
## P assertthat 0.2.1 2019-03-21 [?] CRAN (R 4.1.0)
## P backports 1.2.1 2020-12-09 [?] CRAN (R 4.1.0)
## P broom 0.7.8 2021-06-24 [?] CRAN (R 4.1.0)
## P cachem 1.0.5 2021-05-15 [?] CRAN (R 4.1.0)
## P callr 3.7.0 2021-04-20 [?] CRAN (R 4.1.0)
## P cellranger 1.1.0 2016-07-27 [?] CRAN (R 4.1.0)
## P cli 3.0.0 2021-06-30 [?] CRAN (R 4.1.0)
## P colorspace 2.0-2 2021-06-24 [?] CRAN (R 4.1.0)
## P crayon 1.4.1 2021-02-08 [?] CRAN (R 4.1.0)
## P curl 4.3.2 2021-06-23 [?] CRAN (R 4.1.0)
## P DBI 1.1.1 2021-01-15 [?] CRAN (R 4.1.0)
## P dbplyr 2.1.1 2021-04-06 [?] CRAN (R 4.1.0)
## P desc 1.3.0 2021-03-05 [?] CRAN (R 4.1.0)
## P devtools 2.4.2 2021-06-07 [?] CRAN (R 4.1.0)
## P digest 0.6.27 2020-10-24 [?] CRAN (R 4.1.0)
## P dplyr * 1.0.7 2021-06-18 [?] CRAN (R 4.1.0)
## P ellipsis 0.3.2 2021-04-29 [?] CRAN (R 4.1.0)
## P evaluate 0.14 2019-05-28 [?] CRAN (R 4.1.0)
## P fansi 0.5.0 2021-05-25 [?] CRAN (R 4.1.0)
## P fastmap 1.1.0 2021-01-25 [?] CRAN (R 4.1.0)
## P forcats * 0.5.1 2021-01-27 [?] CRAN (R 4.1.0)
## P fs 1.5.0 2020-07-31 [?] CRAN (R 4.1.0)
## P generics 0.1.0 2020-10-31 [?] CRAN (R 4.1.0)
## P ggplot2 * 3.3.5 2021-06-25 [?] CRAN (R 4.1.0)
## P glue 1.4.2 2020-08-27 [?] CRAN (R 4.1.0)
## P gtable 0.3.0 2019-03-25 [?] CRAN (R 4.1.0)
## P haven 2.4.1 2021-04-23 [?] CRAN (R 4.1.0)
## P highr 0.9 2021-04-16 [?] CRAN (R 4.1.0)
## P hms 1.1.0 2021-05-17 [?] CRAN (R 4.1.0)
## P htmltools 0.5.1.1 2021-01-22 [?] CRAN (R 4.1.0)
## P httr 1.4.2 2020-07-20 [?] CRAN (R 4.1.0)
## P jsonlite 1.7.2 2020-12-09 [?] CRAN (R 4.1.0)
## P kableExtra * 1.3.4 2021-02-20 [?] CRAN (R 4.1.0)
## katereR 0.1.0 2021-07-30 [1] Github (katekathrynkat/katereR@5f2c796)
## P knitr 1.33 2021-04-24 [?] CRAN (R 4.1.0)
## P lifecycle 1.0.0 2021-02-15 [?] CRAN (R 4.1.0)
## P lubridate * 1.7.10 2021-02-26 [?] CRAN (R 4.1.0)
## P magrittr 2.0.1 2020-11-17 [?] CRAN (R 4.1.0)
## P memoise 2.0.0 2021-01-26 [?] CRAN (R 4.1.0)
## P modelr 0.1.8 2020-05-19 [?] CRAN (R 4.1.0)
## P munsell 0.5.0 2018-06-12 [?] CRAN (R 4.1.0)
## P pillar 1.6.1 2021-05-16 [?] CRAN (R 4.1.0)
## P pkgbuild 1.2.0 2020-12-15 [?] CRAN (R 4.1.0)
## P pkgconfig 2.0.3 2019-09-22 [?] CRAN (R 4.1.0)
## P pkgload 1.2.1 2021-04-06 [?] CRAN (R 4.1.0)
## P prettyunits 1.1.1 2020-01-24 [?] CRAN (R 4.1.0)
## P processx 3.5.2 2021-04-30 [?] CRAN (R 4.1.0)
## P ps 1.6.0 2021-02-28 [?] CRAN (R 4.1.0)
## P purrr * 0.3.4 2020-04-17 [?] CRAN (R 4.1.0)
## P R6 2.5.0 2020-10-28 [?] CRAN (R 4.1.0)
## P Rcpp 1.0.6 2021-01-15 [?] CRAN (R 4.1.0)
## P readr * 1.4.0 2020-10-05 [?] CRAN (R 4.1.0)
## P readxl 1.3.1 2019-03-13 [?] CRAN (R 4.1.0)
## P remotes 2.4.0 2021-06-02 [?] CRAN (R 4.1.0)
## renv 0.13.2 2021-03-30 [1] CRAN (R 4.1.0)
## P reprex 2.0.0 2021-04-02 [?] CRAN (R 4.1.0)
## P rlang 0.4.11 2021-04-30 [?] CRAN (R 4.1.0)
## P rmarkdown 2.9 2021-06-15 [?] CRAN (R 4.1.0)
## P rprojroot 2.0.2 2020-11-15 [?] CRAN (R 4.1.0)
## P rstudioapi 0.13 2020-11-12 [?] CRAN (R 4.1.0)
## P rvest 1.0.0 2021-03-09 [?] CRAN (R 4.1.0)
## P scales 1.1.1 2020-05-11 [?] CRAN (R 4.1.0)
## P sessioninfo 1.1.1 2018-11-05 [?] CRAN (R 4.1.0)
## P stringi 1.6.2 2021-05-17 [?] CRAN (R 4.1.0)
## P stringr * 1.4.0 2019-02-10 [?] CRAN (R 4.1.0)
## P svglite 2.0.0 2021-02-20 [?] CRAN (R 4.1.0)
## P systemfonts 1.0.2 2021-05-11 [?] CRAN (R 4.1.0)
## P testthat 3.0.4 2021-07-01 [?] CRAN (R 4.1.0)
## P tibble * 3.1.2 2021-05-16 [?] CRAN (R 4.1.0)
## P tidyr * 1.1.3 2021-03-03 [?] CRAN (R 4.1.0)
## P tidyselect 1.1.1 2021-04-30 [?] CRAN (R 4.1.0)
## P tidyverse * 1.3.1 2021-04-15 [?] CRAN (R 4.1.0)
## P usethis 2.0.1 2021-02-10 [?] CRAN (R 4.1.0)
## P utf8 1.2.1 2021-03-12 [?] CRAN (R 4.1.0)
## P vctrs 0.3.8 2021-04-29 [?] CRAN (R 4.1.0)
## P viridisLite 0.4.0 2021-04-13 [?] CRAN (R 4.1.0)
## P webshot 0.5.2 2019-11-22 [?] CRAN (R 4.1.0)
## P withr 2.4.2 2021-04-18 [?] CRAN (R 4.1.0)
## P xfun 0.24 2021-06-15 [?] CRAN (R 4.1.0)
## P xml2 1.3.2 2020-04-23 [?] CRAN (R 4.1.0)
## P yaml 2.2.1 2020-02-01 [?] CRAN (R 4.1.0)
##
## [1] C:/Users/kathr/Documents/git-repos/lizard-guts-naxos/renv/library/R-4.1/i386-w64-mingw32
## [2] C:/Users/kathr/AppData/Local/Temp/RtmpWMrziP/renv-system-library
##
## P -- Loaded and on-disk path mismatch.